package com.etc.order.provider.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.etc.order.common.domain.ProductCategory;
import com.etc.order.common.service.ProductCategoryService;
import com.etc.order.provider.mapper.ProductCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class ProductCategoryServiceImpl implements ProductCategoryService {
    @Autowired
    private ProductCategoryMapper productCategoryMapper;

    @Override
    public List<ProductCategory> findAllProductCategory(int pageIndex, int pageSize) {
        return productCategoryMapper.findAll(pageIndex, pageSize);
    }

    @Override
    public List<ProductCategory> getType() {
        return productCategoryMapper.getType();
    }

    @Override
    public List<ProductCategory> findByCategoryType(int categoryType) {
        return productCategoryMapper.findByCategoryType(categoryType);
    }

    @Override
    public int getTotalCount(String categoryName) {
        return productCategoryMapper.getTotalCount(categoryName);
    }

    @Override
    public int getTotalCount() {
        return productCategoryMapper.getTotalCount("");
    }

    @Override
    public List<ProductCategory> findByCategoryName(String categoryName, int pageIndex, int pageSize) {
        return productCategoryMapper.findByCategoryName(categoryName, pageIndex, pageSize);
    }

    @Override
    public ProductCategory getOne(int categoryId) {
        return productCategoryMapper.getOne(categoryId);
    }

    @Override
    public int save(ProductCategory category) {
        if (productCategoryMapper.getTotalCount(category.getCategoryName()) > 0) {
            return productCategoryMapper.update(category);
        } else {
            return productCategoryMapper.save(category);
        }
    }

    @Override
    public int delete(int categoryId) {
        return productCategoryMapper.delete(categoryId);
    }
}
